package fr.umlv.proxir.httpmessages;

/**
 * class representing a HTTP request with the following information
 * the host in the request
 * the port (should be 80 for most cases)
 * the first line of the request (METHOD +URL +HTTP/VERSION)
 * @author gourier & motais
 *
 */
public class Request {
	private String host;
	private int port;
	private final String[] pageRequest;
	
	/**
	 * sets the host of the request
	 * @param host
	 */
	public void setHost(String host) {
		this.host = host;
	}

	/**
	 * sets the port of the request
	 * @param port
	 */
	public void setPort(int port) {
		this.port = port;
	}

	/**
	 * creates a request with the requested informations
	 * @param host the host to connect to
	 * @param port the port to connect to 
	 * @param pageRequest the first line of the request parsed with \s
	 */
	public Request(String host, int port, String[] pageRequest) {
		this.host = host;
		this.port = port;
		this.pageRequest=pageRequest;
	}

	/**
	 * return the host of the request
	 * @return the host to connect to
	 */
	public String getHost() {
		return host;
	}

	/**
	 * return the port of the request
	 * @return the port to connect to 
	 */
	public int getPort() {
		return port;
	}

	/**
	 * return the request URL
	 * @return return the page requested
	 */
	public String getPageRequested() {
		return pageRequest[1];
	}
	
	/**
	 * return the method use in this request
	 * @return GET or POST or OPTION etc...
	 */
	public String getMethod(){
		return pageRequest[0];
	}
	
	/**
	 * return the HTTP version of the request
	 * @return 1.1 or 1.0
	 */
	public String getVersion(){
		if(pageRequest.length>2)return pageRequest[2];
		return null;
	}

}
